cmake_minimum_required(VERSION 3.1)

project("tmsg" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES tmsg.cpp tmsg.hpp)
if(MSVC)
    add_compile_options("/source-charset:utf-8")
endif()
include_directories(".")
include_directories("./3rdparty")
include_directories("../paho.mqtt.cpp/install/include" "../paho.mqtt.c/install/include")
find_library(MQTTC NAMES paho-mqtt3a PATHS "../paho.mqtt.c/install/lib")
find_library(MQTTCPP NAMES paho-mqttpp3 PATHS "../paho.mqtt.cpp/install/lib" "../paho.mqtt.cpp/install/bin")
message(STATUS "paho-mqtt3a lib path: " ${MQTTC})
message(STATUS "paho-mqttpp3 lib path: " ${MQTTCPP})
set(MQTTLIB ${MQTTCPP} ${MQTTC})

add_executable(Get example/get.cpp ${SOURCE_FILES})
target_link_libraries(Get ${MQTTLIB})
add_executable(Get2 example/get2.cpp ${SOURCE_FILES})
target_link_libraries(Get2 ${MQTTLIB})
add_executable(GetAll example/getAll.cpp ${SOURCE_FILES})
target_link_libraries(GetAll ${MQTTLIB})
add_executable(Pub example/pub.cpp ${SOURCE_FILES})
target_link_libraries(Pub ${MQTTLIB})

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
include_directories("./example/arduino2tmsg/3rdparty")
add_executable(Arduino2tmsg example/arduino2tmsg/arduino2tmsg.cpp ${SOURCE_FILES})
target_link_libraries(Arduino2tmsg ${MQTTLIB} Threads::Threads)
add_executable(Arduino2tmsg_auto example/arduino2tmsg/arduino2tmsg_auto.cpp ${SOURCE_FILES})
target_link_libraries(Arduino2tmsg_auto ${MQTTLIB} Threads::Threads)